home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 240 < prev    next >
Text File  |  1996-08-06  |  2KB  |  67 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Two questions - Pointer equality and ...
  5. Date: 30 Jan 1996 22:08:08 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan30150808@qcd.lanl.gov>
  8. References: <4elq8a$j0b@taurus.fccc.edu>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: slifker@castor.fccc.edu's message of 30 Jan 1996 19:06:50 GMT
  13.  
  14. In article <4elq8a$j0b@taurus.fccc.edu> slifker@castor.fccc.edu
  15. (Michael J. Slifker) writes: 
  16. <snip>
  17.    Question 1:
  18.  
  19.    According to K&R II, "pointer comparison is defined only for parts
  20.    of the same object". In particular, this is stated to apply to 
  21.    equality operators (== and !=). Harbison & Steele (_C: A Reference
  22.    Manual_) agree with this in the case of relational operators, but
  23.    state that pointer equality is defined provided both operands are
  24.    pointers to compatible types. The latter makes much more sense to
  25.    me, but can anyone tell me what the Standard has to say? 
  26.  
  27. Equality and inequality are defined for any two valid pointers of the
  28. same type, or if one is a pointer to void and the other is a pointer
  29. to an object or incomplete type.
  30.  
  31. <snip>
  32.    Question 2:
  33.  
  34.    I've compiled the following program with gcc:
  35.  
  36.    -----------
  37.  
  38.    #include <stdio.h>
  39.  
  40.    char *str1 = "Hello, World\n";
  41.    const char *str2 = "Hello, World\n";
  42.  
  43.    int main(void)
  44.    {
  45.      str1[0] = 'J';
  46.      printf("%s", str2);
  47.      return 0;
  48.    }
  49.  
  50.    -----------
  51.  
  52.    ...and it prints out "Jello, World". This seems odd, at least to
  53.    me. Is this a bug, or is the behavior above officially undefined?
  54.  
  55. Attempt to modify a string literal results in undefined behaviout. Any
  56. behaviour by the implementation is then valid.
  57.  
  58. Cheers
  59. Tanmoy
  60. --
  61. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  62. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  63. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  64. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  65. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  66. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  67.